package baseTest;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class TreeNumber {
    public static void main(String[] args) {

    }

    public static List<List<Integer>> process(int[] nums){
        if (nums == null || nums.length <3){
            return null;
        }
        List<List<Integer>> ans = new ArrayList<>();
        Arrays.sort(nums);
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] > 0){
                break;
            }
            if (nums[i+1] == nums[i]){
                continue;
            }
            int l = i+1;
            int r = nums.length-1;
            while (l<r){
                int n = nums[i] + nums[l] + nums[r];
                if (n == 0){
                    List<Integer> list = Arrays.asList(nums[i],nums[l],nums[r]);
                    ans.add(list);
                    while(l<r && nums[l] == nums[l+1]){
                        l++;
                    }
                    while(l<r && nums[r] == nums[r-1]){
                        r--;
                    }
                    l++;
                    r--;
                } else if (n < 0){
                    l++;
                } else if (n>0){
                    r--;
                }
            }
        }
        return ans;
    }
}
